#include <jni.h>
#include <string>
#include <android/log.h>


#define LOGW(...)   __android_log_print(ANDROID_LOG_WARN,"ffmpeg android",__VA_ARGS__)


extern "C" {
#include <libavcodec/avcodec.h>
}


extern "C" JNIEXPORT jstring
JNICALL
Java_aiyu_ffmpeg_1android_MainActivity_stringFromJNI(
        JNIEnv *env,
        jobject /* this */) {
    std::string hello = "Hello from C++";
    hello += avcodec_configuration();
    return env->NewStringUTF(hello.c_str());
}

extern "C"
JNIEXPORT jboolean JNICALL
Java_aiyu_ffmpeg_1android_MainActivity_Open(JNIEnv *env, jobject instance, jstring url_,
                                            jobject handle) {
    const char *url = env->GetStringUTFChars(url_, 0);

    // TODO
    FILE * fp = fopen(url, "rb");

    if (!fp) {
        LOGW("file %s open failed !",url);
    } else {
        LOGW("file %s open succued !",url);
    }

    env->ReleaseStringUTFChars(url_, url);

    return 0;
}
